import { ProcessService } from 'src/app/@core/services/process/process.service';
import { Component, Input } from '@angular/core';
import { TableWidthConfig } from 'ng-devui';
import { MomService } from 'src/app/@core/services/mom/mom.service';
@Component({
  selector: 'app-select-process',
  templateUrl: './select-process.component.html',
  styleUrls: ['./select-process.component.scss']
})
export class SelectProcessComponent {
  @Input() data: any;
  isSelected = false;
  displayTableData: any[] = [];
  tableheight = '230px';
  selectData:any;
  searchName:''
  pager = {
    total: 20,
    pageIndex: 1,
    pageSize: 20
  };
  pageSizeOptions = [10, 20, 30, 50, 100];
  dataTableOptions = {
    columns: [
      {
        field:'radio',
        header:'选择',
        fieldType:'radio',
        fixedLeft:'0px'
      },
      {
        field: 'type',
        header: '工序编码',
        fieldType: 'text'
      },
      {
        field: 'type',
        header: '工序名称',
        fieldType: 'text'
      }
    ]
  };
  tableWidthConfig: TableWidthConfig[] = [
    {
      field: 'radio',
      width: '50px'
    },
    {
      field: 'enabled',
      width: '150px'
    },
    {
      field: 'enabled',
      width: '150px'
    }
  ]
  constructor(private MomService:MomService,private ProcessService:ProcessService) { }
  ngOnInit(): void {
   this.ProcessService.GetPagedProcesss(this.searchName,this.pager.pageIndex,this.pager.pageSize).subscribe((res:any)=>{
    this.displayTableData = res.items
    this.pager.total = res.totalCount
   })
  }
  radio(event: any,rowItem:any){
    if(event.target.checked){
      this.isSelected = true;
      this.selectData = rowItem
    }
  }
  pageIndexChange($event: any) {
    this.pager.pageIndex=$event;
    this.ProcessService.GetPagedProcesss(this.searchName,this.pager.pageIndex,this.pager.pageSize).subscribe((res:any)=>{
      this.displayTableData = res.items
      this.pager.total = res.totalCount
     })
  }//切换页码
  pageSizeChange($event: any){
    this.ProcessService.GetPagedProcesss(this.searchName,this.pager.pageIndex,this.pager.pageSize).subscribe((res:any)=>{
      this.displayTableData = res.items
      this.pager.total = res.totalCount
     })
  }//改变每页显示数量
  search(){
    this.ProcessService.GetPagedProcesss(this.searchName,this.pager.pageIndex,this.pager.pageSize).subscribe((res:any)=>{
      this.displayTableData = res.items
      this.pager.total = res.totalCount
     })
  }
  reset(){
    this.searchName = ''
    this.ProcessService.GetPagedProcesss(this.searchName,this.pager.pageIndex,this.pager.pageSize).subscribe((res:any)=>{
      this.displayTableData = res.items
      this.pager.total = res.totalCount
     })
  }
}
